package com.yunshipei.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.yunshipei.common.manager.EnterConfig;
import com.yunshipei.enterplorer.R;

/**
 * Created by cike on 16/3/1.
 */
public class CreateGroupDialog extends Dialog {
    private TextView refrim, quit_group_dialog;
    private EditText nameEditText;
    private View.OnClickListener refrimOnClickListener, quitOnClickListener;
    public CreateGroupDialog(Context context) {
        super(context);
        init(context);
    }

    public CreateGroupDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    protected CreateGroupDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private void init(Context mContext) {
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        View myView = layoutInflater.inflate(R.layout.ysp_create_group_dialog, null);
        refrim = (TextView) myView.findViewById(R.id.refrim);
        int color = EnterConfig.getInstance().getGlobalColor();
        refrim.setTextColor(color);
        quit_group_dialog = (TextView) myView.findViewById(R.id.quit_group_dialog);
        nameEditText = (EditText) myView.findViewById(R.id.editName);
        this.setContentView(myView);
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);
        Window window = getWindow();
        window.setType(WindowManager.LayoutParams.TYPE_APPLICATION);
        WindowManager m = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.8
        //p.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        window.setWindowAnimations(R.style.cike_alert_dialog_anim);
        window.setAttributes(p);
        refrim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                refrimOnClickListener.onClick(v);
            }
        });
        quit_group_dialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                quitOnClickListener.onClick(v);
            }
        });

    }

    public void setRefrimOnClickListener(View.OnClickListener onClickListener) {
        this.refrimOnClickListener = onClickListener;
    }

    public void setQuitOnClickListener(View.OnClickListener onClickListener) {
        this.quitOnClickListener = onClickListener;
    }

    public String getNameEditTextValues() {
        return nameEditText.getText().toString();
    }


}
